<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业管理系统 - 注册</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --accent-color: #4895ef;
            --light-color: #f8f9fa;
            --dark-color: #212529;
            --success-color: #4cc9f0;
            --warning-color: #f72585;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: var(--dark-color);
        }

        .register-container {
            width: 100%;
            max-width: 450px;
            background: white;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            position: relative;
            z-index: 1;
        }

        .register-header {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 30px 20px;
            text-align: center;
            position: relative;
        }

        .register-header h1 {
            font-weight: 500;
            font-size: 1.8rem;
            margin-bottom: 5px;
        }

        .register-header p {
            font-weight: 300;
            opacity: 0.9;
        }

        .register-header::after {
            content: '';
            position: absolute;
            bottom: -20px;
            left: 0;
            right: 0;
            height: 40px;
            background: white;
            transform: skewY(-3deg);
            z-index: -1;
        }

        .register-form {
            padding: 30px;
        }

        .form-group {
            margin-bottom: 20px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark-color);
        }

        .form-control {
            width: 100%;
            padding: 12px 15px 12px 40px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            transition: all 0.3s;
            background-color: #f8f9fa;
        }

        .form-control:focus {
            border-color: var(--accent-color);
            box-shadow: 0 0 0 3px rgba(72, 149, 239, 0.2);
            outline: none;
            background-color: white;
        }

        .input-icon {
            position: absolute;
            left: 15px;
            top: 40px;
            color: #6c757d;
        }

        .btn {
            display: inline-block;
            width: 100%;
            padding: 12px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            text-align: center;
        }

        .btn:hover {
            background: linear-gradient(to right, var(--secondary-color), var(--primary-color));
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .register-footer {
            text-align: center;
            padding: 20px;
            border-top: 1px solid #eee;
            font-size: 0.9rem;
        }

        .register-footer a {
            color: var(--primary-color);
            text-decoration: none;
            transition: color 0.3s;
        }

        .register-footer a:hover {
            color: var(--secondary-color);
            text-decoration: underline;
        }

        .error-message {
            color: var(--warning-color);
            font-size: 0.9rem;
            margin-top: 5px;
            display: none;
        }

        .password-strength {
            margin-top: 5px;
            height: 4px;
            background: #eee;
            border-radius: 2px;
            overflow: hidden;
        }

        .strength-meter {
            height: 100%;
            width: 0;
            transition: width 0.3s, background 0.3s;
        }

        .password-hint {
            font-size: 0.8rem;
            color: #6c757d;
            margin-top: 5px;
        }

        .terms-agreement {
            margin: 20px 0;
            font-size: 0.9rem;
        }

        .terms-agreement input {
            margin-right: 8px;
        }

        .terms-agreement a {
            color: var(--primary-color);
            text-decoration: none;
        }

        .terms-agreement a:hover {
            text-decoration: underline;
        }

        /* 新增角色选择样式 */
        .role-selection {
            margin: 20px 0;
        }

        .role-options {
            display: flex;
            gap: 15px;
            margin-top: 10px;
        }

        .role-option {
            flex: 1;
            position: relative;
        }

        .role-option input[type="radio"] {
            position: absolute;
            opacity: 0;
            width: 0;
            height: 0;
        }

        .role-option label {
            display: block;
            padding: 15px;
            background: #f8f9fa;
            border: 2px solid #ddd;
            border-radius: 8px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
        }

        .role-option input[type="radio"]:checked + label {
            border-color: var(--primary-color);
            background-color: rgba(67, 97, 238, 0.1);
        }

        .role-option label i {
            display: block;
            font-size: 1.5rem;
            margin-bottom: 8px;
            color: var(--primary-color);
        }

        @media (max-width: 480px) {
            .register-container {
                margin: 0 15px;
            }

            .register-header h1 {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
<div class="register-container">
    <div class="register-header">
        <h1>创建新账户</h1>
        <p>加入我们，开始您的旅程</p>
    </div>

    <form class="register-form" action="${pageContext.request.contextPath}/user/register" method="post">
        <c:if test="${not empty error}">
            <div class="error-message" style="display: block;">
                    ${error}
            </div>
        </c:if>

        <div class="form-group">
            <label for="username">用户名</label>
            <i class="fas fa-user input-icon"></i>
            <input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required>
        </div>

        <div class="form-group">
            <label for="email">电子邮箱</label>
            <i class="fas fa-envelope input-icon"></i>
            <input type="email" id="email" name="email" class="form-control" placeholder="请输入电子邮箱" required>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <i class="fas fa-lock input-icon"></i>
            <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required
                   oninput="updatePasswordStrength(this.value)">
            <div class="password-strength">
                <div class="strength-meter" id="strength-meter"></div>
            </div>
            <div class="password-hint">
                密码应包含至少8个字符，包括数字、字母和特殊字符
            </div>
        </div>

        <div class="form-group">
            <label for="confirm-password">确认密码</label>
            <i class="fas fa-lock input-icon"></i>
            <input type="password" id="confirm-password" name="confirmPassword" class="form-control"
                   placeholder="请再次输入密码" required>
        </div>

        <!-- 新增角色选择部分 -->
        <div class="form-group role-selection">
            <label>注册身份</label>
            <div class="role-options">
                <div class="role-option">
                    <input type="radio" id="role-student" name="role" value="1" checked>
                    <label for="role-student">
                        <i class="fas fa-user-graduate"></i>
                        <span>学生</span>
                    </label>
                </div>
                <div class="role-option">
                    <input type="radio" id="role-teacher" name="role" value="2">
                    <label for="role-teacher">
                        <i class="fas fa-chalkboard-teacher"></i>
                        <span>教师</span>
                    </label>
                </div>
            </div>
        </div>

        <div class="terms-agreement">
            <input type="checkbox" id="agree-terms" name="agreeTerms" required>
            <label for="agree-terms">我已阅读并同意<a href="#">服务条款</a>和<a href="#">隐私政策</a></label>
        </div>

        <button type="submit" class="btn">注 册</button>
    </form>

    <div class="register-footer">
        已有账户? <a href="${pageContext.request.contextPath}/login">立即登录</a>
    </div>
</div>

<script>
    function updatePasswordStrength(password) {
        const strengthMeter = document.getElementById('strength-meter');
        let strength = 0;

        // 长度检查
        if (password.length >= 3) strength += 1;
        if (password.length >= 3) strength += 1;

        // 包含数字
        if (/\d/.test(password)) strength += 1;

        // 包含小写字母
        if (/[a-z]/.test(password)) strength += 1;

        // 包含大写字母
        if (/[A-Z]/.test(password)) strength += 1;

        // 包含特殊字符
        if (/[^a-zA-Z0-9]/.test(password)) strength += 1;

        // 更新强度条
        let width = 0;
        let color = '#f72585'; // 红色

        if (strength <= 2) {
            width = 33;
            color = '#f72585'; // 红色
        } else if (strength <= 4) {
            width = 66;
            color = '#f8961e'; // 橙色
        } else {
            width = 100;
            color = '#4cc9f0'; // 绿色
        }

        strengthMeter.style.width = width + '%';
        strengthMeter.style.background = color;
    }
</script>
</body>
</html>